#pragma once

#include <string>
#include <map>
#include <list>
#include <algorithm>
#include <string.h>
#include <mutex>
#include "bondlib.h"

class CExchangeRepoUnit{
public:
	char RateKey[16];		//键值
	char ID[8];				//ID
	char Code[8];			//代码
	char Name[64];			//名称
	char ListedMarket[8];	//所在市场

	const bool operator < (const CExchangeRepoUnit& one) const  
	{  
		return strcmp(RateKey, one.RateKey) < 0;
	} 
	const bool operator == (const CExchangeRepoUnit& one)
	{
		return strcmp(RateKey, one.RateKey) == 0;
	}
};

class S_BONDLIB_EXPORT CExchangeRepoInfo
{
public:
	static CExchangeRepoInfo& instance();
public:
	const CExchangeRepoUnit* GetItem(const char* strID);

	void	Clear( );
	void	Add(CExchangeRepoUnit& one);
	int		GetSize();

	std::mutex&  GetMutex() {return m_mutex;}

	const std::map<std::string,CExchangeRepoUnit>& GetData() const {return m_map;}
public:
	void DumpStatus(int mode = 0)const;
private:
	CExchangeRepoInfo();
	virtual ~CExchangeRepoInfo();
private:
	std::map<std::string,CExchangeRepoUnit>  m_map;
	std::mutex			m_mutex;
};
